﻿
using AntMovement.Core.Entity;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace AntMovement.SDK.LTSMC.Domain.Update
{
    public class HardwareUpdateDO : AntMovement.Core.IHardwareUpdate
    {
        private List<DO> _values = new List<DO>();
        private int _nCardNo;
        private int _index;

        public HardwareUpdateDO(int nCardNo, int index, DO[] values)
        {
            _nCardNo = nCardNo;
            _index = index;
            _values.AddRange(values);
        }

        public string Update()
        {
            uint data = LTSMC.smc_read_outport((ushort)_values[0].CardNo, (ushort)_values[0].MdlIndex);
            //if (data != 0) { return $"CardNo[{_nCardNo}] Index[{_index}] smc_read_inport ==>> {data}"; }
            int i = 0;
            _values[i].Status = ((data >> i) & 0x01) == 0;
            i = 1;
            _values[i].Status = ((data >> i) & 0x01) == 0;
            i = 2;
            _values[i].Status = ((data >> i) & 0x01) == 0;
            i = 3;
            _values[i].Status = ((data >> i) & 0x01) == 0;
            i = 4;
            _values[i].Status = ((data >> i) & 0x01) == 0;
            i = 5;
            _values[i].Status = ((data >> i) & 0x01) == 0;
            i = 6;
            _values[i].Status = ((data >> i) & 0x01) == 0;
            i = 7;
            _values[i].Status = ((data >> i) & 0x01) == 0;
            i = 8;
            _values[i].Status = ((data >> i) & 0x01) == 0;
            i = 9;
            _values[i].Status = ((data >> i) & 0x01) == 0;
            i = 10;
            _values[i].Status = ((data >> i) & 0x01) == 0;
            i = 11;
            _values[i].Status = ((data >> i) & 0x01) == 0;
            i = 12;
            _values[i].Status = ((data >> i) & 0x01) == 0;
            i = 13;
            _values[i].Status = ((data >> i) & 0x01) == 0;
            i = 14;
            _values[i].Status = ((data >> i) & 0x01) == 0;
            i = 15;
            _values[i].Status = ((data >> i) & 0x01) == 0;
            if (_values.Count > 16)
            {
                i = 16;
                _values[i].Status = ((data >> i) & 0x01) == 0;
                i = 17;
                _values[i].Status = ((data >> i) & 0x01) == 0;
                i = 18;
                _values[i].Status = ((data >> i) & 0x01) == 0;
                i = 19;
                _values[i].Status = ((data >> i) & 0x01) == 0;
                i = 20;
                _values[i].Status = ((data >> i) & 0x01) == 0;
                i = 21;
                _values[i].Status = ((data >> i) & 0x01) == 0;
                i = 22;
                _values[i].Status = ((data >> i) & 0x01) == 0;
                i = 23;
                _values[i].Status = ((data >> i) & 0x01) == 0;
                i = 24;
                _values[i].Status = ((data >> i) & 0x01) == 0;
                i = 25;
                _values[i].Status = ((data >> i) & 0x01) == 0;
                i = 26;
                _values[i].Status = ((data >> i) & 0x01) == 0;
                i = 27;
                _values[i].Status = ((data >> i) & 0x01) == 0;
                i = 28;
                _values[i].Status = ((data >> i) & 0x01) == 0;
                i = 29;
                _values[i].Status = ((data >> i) & 0x01) == 0;
                i = 30;
                _values[i].Status = ((data >> i) & 0x01) == 0;
                i = 31;
                _values[i].Status = ((data >> i) & 0x01) == 0;
            }
            return "ok";
        }
    }
}
